package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.dto.e.RpsTalkEntDTO;
import com.macro.mall.dto.o.RpsTalkOutDTO;
import com.macro.mall.mapper.RpsTopicResultMapper;
import com.macro.mall.model.RpsTopicResult;
import com.macro.mall.service.RpsTalkService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RpsTalkServiceImpl implements RpsTalkService {
    @Autowired
    private RpsTopicResultMapper rpsTopicResultMapper;
    @Override
    public PageInfo<RpsTalkOutDTO> list(RpsTalkEntDTO rpsTalkEntDTO) {
        PageHelper.startPage(rpsTalkEntDTO.getPage(),rpsTalkEntDTO.getPageSize());
        List<RpsTopicResult> list = rpsTopicResultMapper.list(rpsTalkEntDTO.getDataType());
        PageInfo<RpsTopicResult> rpsTopicResultPageInfo = new PageInfo<>(list);
        List<RpsTalkOutDTO> list1=new ArrayList<>();
        for (RpsTopicResult rpsTopicResult:list){
            RpsTalkOutDTO rpsTalkOutDTO = new RpsTalkOutDTO();
            BeanUtils.copyProperties(rpsTopicResult,rpsTalkOutDTO);
            list1.add(rpsTalkOutDTO);
        }
        PageInfo<RpsTalkOutDTO> rpsTalkOutDTOPageInfo = new PageInfo<>(list1);
        rpsTalkOutDTOPageInfo.setTotal(rpsTopicResultPageInfo.getTotal());
        return rpsTalkOutDTOPageInfo;
    }

    @Override
    public int modify(RpsTalkEntDTO rpsTalkEntDTO) {
        RpsTopicResult rpsTopicResult = new RpsTopicResult();
        BeanUtils.copyProperties(rpsTalkEntDTO,rpsTopicResult);
        return rpsTopicResultMapper.updateByPrimaryKeySelective(rpsTopicResult);
    }
}
